/*
 * TestProbabilityVector.java
 *
 * Created on 21 de Julho de 2011, 14:21
 *
 */

package intopo.demonstrator;

import cern.jet.random.engine.MersenneTwister;
import intopo.partnerselection.ProbabilityVector;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 21 de Julho de 2011
 */
public class TestProbabilityVector
{
	static public void main (String[] args)
	{
		double f = 0.1;
		for (int i = 0; i < 7; i++) {
			f += 0.1;
		}
		while (f != Math.rint (f)) {
			System.out.format ("%30.12f %16X %16X %32.12f\n",
				Math.rint (f), Double.doubleToLongBits (Math.rint (f)),
				Double.doubleToLongBits (f), f);
			f *= 10;
		}
		MersenneTwister supply = new MersenneTwister (new java.util.Date ());
		int[][] p = {
			{100, 200, 400, 800},
			{1, 1}, {100, 100},
			{1, 2, 4, 8},
			{0, 2, 0, 8},
			{0, 0, 2, 0, 0, 8, 0, 0},
			{0, 0, 2, 2, 0, 0, 8, 8, 0, 0},
			{0, 1, 0, 4, 0},
			{0, 0, 1, 0, 0, 4, 0, 0},
			{0, 0, 1, 1, 0, 0, 4, 4, 0, 0},
			{0, 0, 1, 1, 0, 0, 1, 1, 0, 0},
			{1, 2}};
		for (int[] probabilities : p) {
			ProbabilityVector pv = new ProbabilityVector (probabilities);
			int[] quantity = new int [probabilities.length];
			for (int trial = 1500 * 1000; trial > 0; trial--) {
				int selected = pv.randomCombination (supply);
				quantity [selected]++;
			}
			// print horizontally
			for (int i = 0; i < probabilities.length; i++) {
				System.out.format (" %8d#", probabilities [i]);
			}
			System.out.println ();
			for (int i = 0; i < probabilities.length; i++) {
				System.out.format (" %9d", quantity [i]);
			}
			System.out.println ();
//			// print vertically
//			for (int i = 0; i < probabilities.length; i++) {
//				System.out.format (" %3d#%9d\n", probabilities [i], quantity [i]);
//			}
			System.out.println ();
		}
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
